CREATE PROCEDURE coreCmsCreateNew
(
	@cid				int output,
	@vid				int output,	
	@FK_ParentID		int,
	@FK_STypeID			nvarchar(250),
	@NodeTitle			nvarchar(500),
	@NodeName			nvarchar(100),
	@NodePath			nvarchar(4000),
	@UserIDOwner		int,
	@HasEmbargoStart	bit,
	@PublishStartDT		datetime,
	@HasEmbargoEnd		bit,
	@PublishUntilDT		datetime,
	@ExpiryActionID		int,
	@ExpiryActionDataID	int,
	@XMLData			xml
)
AS
BEGIN
	SET NOCOUNT ON;

	/* Declarations */
	DECLARE		@nextRank		int;
	DECLARE		@contentID		int;
	DECLARE		@versionID		int;
	
	/* Get the next rank number at this parent level */
	SELECT @nextRank = (ISNULL(MAX(Rank),0))+1 FROM Content WHERE FK_ParentID=@FK_ParentID;
	
	/* Create the content record */
	INSERT INTO Content 
		(
		FK_ParentID, Rank, FK_STypeID, NodeTitle, NodeName, NodePath, CreatedDT,
		FK_CreatedBy, LastModifiedDT, FK_LastModifiedBy, WorkflowModeID, WorkflowStatus,
		FK_CheckedOutTo, CheckedOutDT, CurrentVersionNumber, HasEmbargoStart, PublishStartDT,
		HasEmbargoEnd, PublishUntilDT, ExpiryActionID, ExpiryActionDataID, HasOwnSecurity,
		FK_LiveV, FK_VersionV
		)
	VALUES 
		(
		@FK_ParentID, @nextRank, @FK_STypeID, @NodeTitle, @NodeName, @NodePath, GETDATE(),
		@UserIDOwner, GETDATE(), @UserIDOwner, -1, 0,
		@UserIDOwner, GETDATE(), 1, @HasEmbargoStart, @PublishStartDT,
		@HasEmbargoEnd, @PublishUntilDT, @ExpiryActionID, @ExpiryActionDataID, 0,
		-1, -1
		);
	SELECT @contentID = @@IDENTITY;
	
	/* Create the content V record */
	INSERT INTO ContentV
		(
		FK_ContentID, VersionNumber, FK_CheckedInBy, CheckedInDT, VersionNotes, XMLData
		)
	VALUES
		(
		@contentID, 1, -1, GETDATE(), '', @XMLData
		);
	SELECT @versionID = @@IDENTITY;
	
	/* Link up the two records */
	UPDATE Content SET FK_VersionV = @versionID WHERE PK_ID=@contentID;

	/* SET RESULTS */
	SELECT @cid = @contentID, @vid = @versionID;

	SET NOCOUNT OFF;	
END